/*
	flad : Copyright 2010 Dale J Williams

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/
package lads.flad {
	
	import lads.flad.input.KeyboardManager;
	import lads.flad.load.LoadManager;
	import lads.flad.screens.ScreenManager;
	import lads.flad.sound.SoundManager;
	import lads.flad.tween.TweenManager;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * GameCore: Grants access to the core elements of the game.
	 * @author Dale J Williams
	 * @version 1.5
	 */
	public class GameCore {
		
		static public const VERSION		:String		= "v1.0a";
		
		static private var _instance	:GameCore;
		
		private var _loader		:LoadManager 		= new LoadManager();
		private var _tween		:TweenManager		= new TweenManager();
		private var _input		:KeyboardManager;
		private var _screen		:ScreenManager;
		private var _sound		:SoundManager;
		private var _engine		:GameEngine;
		private var _stage		:Stage;
		private var _cont		:Sprite;
		private var _overlay	:Sprite;
		private var _gameXML	:XML;
		private var _path		:String;
		private var _width		:Number;
		private var _height		:Number;
		
		public function GameCore(stage:Stage) {
			trace("flad " + VERSION);
			
			_instance = this;
			_stage = stage;
			
			_cont = new Sprite();
			stage.addChild(_cont);
			stage.addEventListener(Event.RESIZE, stageResize);
			stageResize(null);
			
			_engine = new GameEngine(this);			
			_input = new KeyboardManager(_stage);
			_screen = new ScreenManager(_cont);
			_screen.core = this;
			_sound = new SoundManager();
		}
		
		private function stageResize(e:Event):void {
			_width = _stage.stageWidth;
			_height = _stage.stageHeight;
		}
		
		public function get stage():Stage { return _stage; }
		
		public function get path():String { return _path; }
		
		public function get loader():LoadManager { return _loader; }
		
		public function get screen():ScreenManager { return _screen; }
		
		public function get input():KeyboardManager { return _input; }
		
		public function get width():Number { return _width; }
		
		public function get height():Number { return _height; }
		
		public function get tween():TweenManager { return _tween; }

		public function get engine():GameEngine { return _engine; }		
		public function set engine(value:GameEngine):void {
			_engine = value;
		}
		
		public function get sound():SoundManager { return _sound; }
		
		public function get overlay():Sprite { return _overlay; }
		
		static public function get instance():GameCore { return _instance; }
		
		public function get gameXML():XML { return _gameXML; }		
		public function set gameXML(value:XML):void {
			_gameXML = value;
		}
		
	}

}